<template>
	<view class="page">
		<view class="header">
			 <!-- 使用 v-if 和 v-else 来判断是否显示用户头像或默认头像 -->
			<image :src="userInfo.user_pic" class="touxiang" mode="" v-if="userInfo.user_pic" />
			<image src="../../static/logo.png" class="touxiang" mode="" v-else />
			<view class="right">
				<view class="text" v-if="userInfo.phoneNum">
				{{userInfo.phoneNum}}
				</view>
				<view class="text" @click="login" v-else>点击登录</view>
				<view class="iconfont icon-shezhi" @click="toMySet"></view>
			</view>
			
		</view>
		
		<view id="user-info-form">
			<view class="form" @click="toApply">
				<view class="iconfont icon-dingdan"></view>
				<view>申请接单</view>
			    <view class="iconfont icon-arrow-right-copy-copy-copy"></view>
			</view>
			<view>
				<view>问题请点击微信客服复制微信添加好友</view>
					<view class="form" @click="getWXCustomer">
					<view class="iconfont icon-weixin"></view>
						<view>微信客服</view>
						<view class="iconfont icon-arrow-right-copy-copy-copy"></view>
				</view>	
				<view class="form" @click="toAboutAs">
						<view class="iconfont icon-bangzhuguanyuwomen"></view>
						<view>关于我们</view>
						<view class="iconfont icon-arrow-right-copy-copy-copy"></view>
				</view>
				<view class="form" @click="toProposal">
						<view class="iconfont icon-tousujianyi"></view>
						<view>投诉建议</view>
						<view class="iconfont icon-arrow-right-copy-copy-copy"></view>
				</view>
			</view>
			
		    
		</view>
		<view class="my-btn" @click="goUpdatePwd">
		        修改密码
		</view>
		<view class="my-btn" @click="loginOut" v-if="userInfo.phoneNum">
		        退出登录
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:null,
				// userInfo.user_pic:'',
				// nick_name:"",
				
			}
		},
		created() {
			//获取存储在storage中的userInfo数据 name token userInfo
			this.userInfo = uni.getStorageSync("userInfo") || {};
			this.userInfo = userInfo
			console.log(this.userInfo)
			// let obj ={
			// 	name:"ll",
			// 	age:18,
			// 	name:"lll"
			// }
			// let obj1={...obj,name:"llll"}
			// console.log(obj,obj1,"obj对象");
			
			// let arr = [1,2,3]
			
			// let arr1=arr
			// arr[0]=999
			
			// console.log(arr,arr1,"arr数组");
			//...展开运算符 可以用数组或者对象的深拷贝
			//浅拷贝指的只是复制地址，深拷贝指的是复制值
			
		},
		methods: {
			toProposal(){
				uni.navigateTo({
					url:'/pages/proposal/proposal'
				})
			},
			goUpdatePwd(){
				uni.navigateTo({
					url:'/pages/updatedPassword/updatedPassword'
				})
			},
			toAboutAs(){
				uni.navigateTo({
					url:'/pages/aboutAs/aboutAs'
				})
			},
			toApply(){
				uni.navigateTo({
					url:'/pages/apply/apply'
				})
			},
			loginOut(){
				uni.removeStorageSync('token');
				uni.removeStorageSync('userInfo');
				uni.reLaunch({
					url:'/pages/login/login'
				})
			},
			login(){
				uni.removeStorageSync('token');
				uni.removeStorageSync('userInfo');
				uni.reLaunch({
					url:'/pages/login/login'
				})
			},
			toMySet(){
				uni.navigateTo({
					url:'/pages/mySet/mySet'
				})
			},
			getWXCustomer(){
				uni.setClipboardData({
					data: '12322222222',
					showToast:true
				})
			},
			// 新增方法，用于更新userInfo
			    updateUser() {
			      this.userInfo = uni.getStorageSync("userInfo") || {};
			},
		},
		// 监听器，监听userInfo的变化
		  watch: {
		    "userInfo.user_pic"(newVal, oldVal) {
		      // 当用户头像更新后，做一些操作，比如重新加载页面或者组件
		      // 这里只是打印新旧头像地址
		      console.log("头像更新了", newVal, oldVal);
		    },
		  },
	}
</script>

<style lang="scss" scoped>
.page{
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    // display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
	.header{
		padding-left: 15px;
		height: 80px;
		background-color: #b2cfed;
		display: flex;
		.right{
			margin-top: 10px;
			margin-left: 130px;
			display: flex;
			// margin: auto;
			// padding-left: 400rpx;
			// display: inline; 
			float: right;
			// justify-content: flex-end;
		}
		.images {
						display: flex;
					}
					image {
						width: 60rpx;
						height: 60rpx;
						margin-right: 10px;
						margin-top: 20rpx;
					}
	}
	#user-info-form{
		background-color: white;
		padding: 20px;
		border-radius: 10px;
		box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
		width: 250px;
		margin: 0px 20px;
		.form {
		    margin-bottom: 15px;
			display: flex;
			.icon-arrow-right-copy-copy-copy{
				justify-content: flex-end;
				float: right;
				
			}
		}

	}
	.my-btn{
		width: 85%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		background-color: rgb(224, 7, 36);
		margin: 10px 20px;
		border-radius: 40rpx;
		color:#fff;
	}
}




</style>
